package com.tutorialspoint.tranc;

import java.util.List;
import com.tutorialspoint.base.MyBase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp extends MyBase {
	public static void main(String[] args) {
		ApplicationContext ctx = 
				new ClassPathXmlApplicationContext("Beans.xml");
		StudentJDBCTemplate studentJDBCTemplate = 
				(StudentJDBCTemplate) ctx.getBean("studentJDBCTemplate");    
	    System.out.println("------Records creation--------" );
	    studentJDBCTemplate.create("Zara", 11, 99, 2010);
	    studentJDBCTemplate.create("Nuha", 20, 97, 2010);
	    studentJDBCTemplate.create("Ayan", 25, 100, 2011);
	    System.out.println("------Listing all the records--------" );
	    List<StudentMarks> studentMarks = studentJDBCTemplate.listStudents();
	    for (StudentMarks record : studentMarks) {
	       System.out.print("ID : " + record.getId());
	       System.out.print(", Name : " + record.getName());
	       System.out.print(", Marks : " + record.getMarks());
	       System.out.print(", Year : " + record.getYear());
	       System.out.println(", Age : " + record.getAge());
	     }
	    
	    ApplicationContext ctx1 = 
				new ClassPathXmlApplicationContext("Beans2.xml");
		StudentDAO studentJDBCTemplate2 = 
				(StudentDAO) ctx1.getBean("studentJDBCTemplate2");    
	    System.out.println("------StudentJDBCTemplate2 Records creation--------" );
	    studentJDBCTemplate2.create("Zara", 11, 99, 2010);
	    MainApp.closeContext(ctx);
	    MainApp.closeContext(ctx1);
	}
}
